#include <reg52.h>

#define SMG_DROP P0
#define u8 unsigned char
#define u16 unsigned int

sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;

u8 gsmg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
				          0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

u8 a,b,c,d,e,f,g,h;									

void delay(u16 ten)
{
  while(ten--);
}	

void smg()
{
	LSA = 1;LSB = 1;LSC = 1;
	SMG_DROP = gsmg_code[a];
	delay(100);
	LSA = 0;LSB = 1;LSC = 1;
	SMG_DROP = gsmg_code[b];
	delay(100);
	LSA = 1;LSB = 0;LSC = 1;
	SMG_DROP = gsmg_code[c];
	delay(100);
	LSA = 0;LSB = 0;LSC = 1;
	SMG_DROP = gsmg_code[d];
	delay(100);
	LSA = 1;LSB = 1;LSC = 0;
	SMG_DROP = gsmg_code[e];
	delay(100);
	LSA = 0;LSB = 1;LSC = 0;
	SMG_DROP = gsmg_code[f];
	delay(100);
	LSA = 1;LSB = 0;LSC = 0;
	SMG_DROP = gsmg_code[g];
	delay(100);
	LSA = 0;LSB = 0;LSC = 0;
	SMG_DROP = gsmg_code[h];
	delay(100);
}

void main()
{
	while(1)
	{
		a++;
		if(a > 9)
		{
			b++;
			a = 0;
			if(b > 9)
			{
				c++;
				b = 0;
				if(c > 9)
				{
					d++;
					c = 0;
					if(d > 9)
					{
						e++;
						d = 0;
						if(e > 9)
						{
							f++;
							e = 0;
							if(f > 9)
							{
								g++;
								f = 0;
								if(g > 9)
								{
									h++;
									g = 0;
								}
							}
						}
					}
				}
			}
		}
		smg();
		delay(200);
	}
}